<template>
    <div>
      <div class="mainapp">
        <div class="app-container">
          <div class="header">
            <el-form :inline="true" :model="formInline" class="demo-form-inline">
              <el-form-item label="月份">
                <el-date-picker
                  v-model="formInline.month"
                  value-format="yyyy-MM"
                  type="month"
                  :disabled="$route.query.month?true:false"
                  :picker-options="pickerOptions"
                  placeholder="选择月">
                </el-date-picker>
              </el-form-item>
            </el-form>
          </div>
          <el-card>
            <el-form :mode="normList">
              <div v-for="(item,index) in (list.length>0?list:normList)" :key="index">
                <div class="biaoti">{{item.corpName}}</div>
                <div style="padding:0 240px">
                  <div class="neirong" style="width:49%;display: inline-block;" v-for="(e,n) in item.dataList" :key="n">
                    <div class="neiTlitle">
                      {{e.indexName}}
                    </div>
                    <div>
                      <el-form-item
                      >

                        <el-input style="width:540px" v-model="e.value"></el-input>
                      </el-form-item>
                    </div>
                  </div>
                </div>

              </div>
            </el-form>
            <div class="btn">
              <el-button @click="btnSave">保存</el-button>
              <el-button type="primary" @click="btn">提交</el-button>
            </div>
          </el-card>

        </div>
      </div>
    </div>
</template>

<script>
  import {getNormList,getbtnList,saveUploadDataInfoById,saveUploadDataInfo,queryInsertDataById,insertUploadDataById} from "@/api/escalation";
    export default {
        name: "index",
        data(){
            return {
                formInline:{
                    month:''
                },
                pickerOptions:{
                    disabledDate(time) {
                        // return time.getTime() >Date.now() - 8.64e7;
                    }
                },
                normList:[],
                btnlist:[],
                list:[],
            }
        },
        methods:{
            getNormList(){
                getNormList().then((res=>{
                     console.log(res);
                     this.normList = res.data;

                }))
            },
            btn(){
                if(this.$route.query.id){
                    if(this.formInline.month){
                        this.list.forEach((item=>{
                            item.dataList.forEach((i=>{
                                this.btnlist.push({dataId:i.id,dataContt:i.value,setupTm:this.formInline.month,infoId:this.$route.query.id})
                            }))
                        }))
                        insertUploadDataById(this.btnlist).then((res=>{
                            if(res.insertFlag==false){
                                this.$message.info(res.message);
                            }else{
                                this.$message.info('填报成功')
                                this.$router.push({path:'/reporthome/repostList'})
                            }
                            console.log(res)
                        }))
                        this.btnlist=[];
                    }else{
                        console.log(this.normList);
                        this.$message.info('请选择日期，提交')
                    }
                }else{
                    if(this.formInline.month){
                        this.normList.forEach((item=>{
                            item.dataList.forEach((i=>{
                                this.btnlist.push({dataId:i.id,dataContt:i.value,setupTm:this.formInline.month})
                            }))
                        }))
                        getbtnList(this.btnlist).then((res=>{
                            if(res.insertFlag==false){
                                this.$message.info(res.message);
                            }else{
                                this.$message.info('填报成功')
                                this.$router.push({path:'/reporthome/repostList'})
                            }
                            console.log(res)
                        }))
                        this.btnlist=[];
                    }else{
                        console.log(this.normList);
                        this.$message.info('请选择日期，提交')
                    }
                }
            },
            btnSave(){
                if(this.$route.query.id){
                    if(this.formInline.month){
                        this.list.forEach((item=>{
                            item.dataList.forEach((i=>{
                                this.btnlist.push({dataId:i.id,dataContt:i.value,setupTm:this.formInline.month,infoId:this.$route.query.id})
                            }))
                        }))
                        saveUploadDataInfoById(this.btnlist).then((res=>{
                            if(res.insertFlag==false){
                                this.$message.info(res.message);
                            }else{
                                this.$message.info('保存成功')
                                this.$router.push({path:'/reporthome/repostList'})
                            }
                            console.log(res)
                        }))
                        this.btnlist=[];
                    }else{
                        console.log(this.normList);
                        this.$message.info('请选择日期，提交')
                    }
                }else{
                    if(this.formInline.month){
                        this.normList.forEach((item=>{
                            item.dataList.forEach((i=>{
                                this.btnlist.push({dataId:i.id,dataContt:i.value,setupTm:this.formInline.month})
                            }))
                        }))
                        saveUploadDataInfo(this.btnlist).then((res=>{
                            if(res.insertFlag==false){
                                this.$message.info(res.message);
                            }else{
                                this.$message.info('保存成功')
                                this.$router.push({path:'/reporthome/repostList'})
                            }
                            console.log(res)
                        }))
                        this.btnlist=[];
                    }else{
                        console.log(this.normList);
                        this.$message.info('请选择日期，提交')
                    }
                }
            },
        },
        created(){
            this.getNormList();
        },
        mounted() {
            if(this.$route.query.month){
                queryInsertDataById({id:this.$route.query.id}).then((response) => {
                    console.log(response.data,'response')
                    if(response.data.length>0){
                        this.list = response.data;
                    }
                })
            }
            this.formInline.month = this.$route.query.month;
            console.log(this.list,this.$route.query.month)
        }
    }
</script>

<style scoped lang="scss">
  .biaoti{
    /*margin: 20px 0;*/
    height: 48px;
    line-height: 48px;
    background: #F8F8F9;
    border-radius: 4px 4px 0px 0px;
    padding-left:18px;
    margin-bottom: 31px;
  }
 .neirong{
    height:100px;
    /*background:#cccccc;*/
    border-radius: 5px;
   margin: 5px 0;
   .neiTlitle{
      margin-bottom: 10px;
   }
 }
  .btn{
    margin: 10px 20px;
    text-align: center;
  }
  ::v-deep .el-card__body{
    padding:0px
  }
</style>
